package routers

import (
	"net/http"
	"web/api"
	"web/middleware"
	"web/pkg/upload"

	"github.com/gin-gonic/gin"
)

func InitRouter() *gin.Engine {
	r := gin.New()
	r.Use(gin.Logger(), gin.Recovery()) // 手动添加Logger和Recovery中间件
	r.Use(middleware.Cors()) //处理跨域资源共享

	r.StaticFS("/upload/images", http.Dir(upload.GetImageFullPath()))
	//r.StaticFS("/export", http.Dir(export.GetExcelFullPath())) //处理excel的东西
	//r.StaticFS("/qrcode", http.Dir(qrcode.GetQrCodeFullPath())) //二维码

	// 认证路由（不需要JWT验证）
	r.POST("/auth", GetAuth)
	
	// 图片上传路由
	r.POST("/upload/image", UploadImage)

	// API路由组
	tagController := new(api.TagController)
	apiGroup := r.Group("/api")
	{
		// 标签相关路由
		apiGroup.GET("tags", tagController.GetTags)
		apiGroup.POST("tags", tagController.CreateTag)
		apiGroup.PUT("tags/:id", tagController.UpdateTag)
		apiGroup.GET("tags/:id", tagController.GetTag)
		apiGroup.DELETE("tags/:id", tagController.DeleteTag)

		// 订单相关路由
		SetupOrderRoutes(apiGroup)
	}

	return r
}
